package com.heima.tess4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class Application {
    public static void main(String[] args) throws TesseractException {
        //获取本地图片
        File file = new File("D:\\图片\\7e54f72e973a8daf6aa215d454335a77.png");
        //创建Tesseract对象
        ITesseract tesseract = new Tesseract();
        //设置字体库路径
        tesseract.setDatapath("D:\\tessdata");
        //中文识别
        tesseract.setLanguage("chi_sim");
        //执行ocr识别
        String result = tesseract.doOCR(file);
        //替换回车和tal键  使结果为一行
        result = result.replaceAll("\\r|\\n","-").replaceAll(" ","");
        System.out.println("识别的结果为："+result);
    }
}
